package com.zhang.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;

@Component
public class TestFilter extends AbstractGatewayFilterFactory implements Ordered {
    Logger logger = LoggerFactory.getLogger(TestFilter.class);


    public GatewayFilter apply(Object config) {
        return (exchange, chain) -> {
            ServerHttpRequest request = exchange.getRequest();
            ServerHttpResponse response = exchange.getResponse();
            logger.info("TestFilter =  =  =  =  =  = 执行了=  =  =  =  =  =  =  =");
            return chain.filter(exchange);
        };
    }

    public int getOrder() {
        return 0;
    }


//    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//        logger.info("=============TestFilter=============");
//        return chain.filter(exchange);
//    }
//
//    public int getOrder() {
//        return 0;
//    }
}
